package cn.net.xyan.easy.webapp.base.entity;

import cn.net.xyan.easy.spring.jpa.utils.sequence.TableSequenceGenerator;
import cn.net.xyan.easy.webapp.base.entity.status.PermissionGroupStatus;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by xiashenpin on 16/1/23.
 */
@Entity
@Table(name = "t_sys_permission_group")
public class PermissionGroup {
    String sequence;
    String groupName;
    String describe;
    List<Permission> permissions =new LinkedList<>();
    List<SystemUser> users;
    PermissionGroupStatus status;

    public PermissionGroup(){

    }

    public PermissionGroup(String groupName){
        this.groupName = groupName;
    }

    @Id
    @Column(name = "id",unique = true,updatable = false,nullable = false,length = 32)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = PermissionGroup_.SEQUENCE_)
    @GenericGenerator(name = PermissionGroup_.SEQUENCE_,
            strategy = TableSequenceGenerator.STRATEGY,
            parameters = {
                    @org.hibernate.annotations.Parameter(name = "format", value = "PG0000000")
                    //@org.hibernate.annotations.Parameter(name = "formatClass", value = ArchiveIDFormat.FormatClass)
            })
    public String getSequence() {
        return sequence;
    }

    public void setSequence(String sequence) {
        this.sequence = sequence;
    }

    @Column(name = "groupName",nullable = false,unique = true)
    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public String getDescribe() {
        return describe;
    }

    public void setDescribe(String describe) {
        this.describe = describe;
    }

    @ManyToMany
    @JoinTable(name = "t_sys_permission_group_join")
    public List<Permission> getPermissions() {
        return permissions;
    }

    public void setPermissions(List<Permission> permissions) {
        this.permissions = permissions;
    }

    @ManyToMany(mappedBy = "permissionGroups")
    public List<SystemUser> getUsers() {
        return users;
    }

    public void setUsers(List<SystemUser> users) {
        this.users = users;
    }

    @ManyToOne
    @JoinColumn(name = "status")
    public PermissionGroupStatus getStatus() {
        return status;
    }

    public void setStatus(PermissionGroupStatus status) {
        this.status = status;
    }
}
